package com.hz.web.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.hz.web.dao.AreaDepartmentDao;
import com.hz.web.entity.AreaDepartmentEntity;
import com.hz.web.service.IAreaDepartmentService;
import com.hz.web.util.Uid;

@Service
public class AreaDepartmentImpl implements IAreaDepartmentService {
	
	@Resource
	private AreaDepartmentDao areadepartmentDao;
	
	/**
	 * 添加部门信息
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int AddAreaDepartment(AreaDepartmentEntity entity) {
		entity.setId(Uid.getUid());
		return areadepartmentDao.AddAreaDepartment(entity);
	}

	/**
	 * 查询部门信息
	 * @param parmsMap
	 * @return
	 */
	@Override
	public List<AreaDepartmentEntity> selectAreaDepartment(AreaDepartmentEntity entity,int page ,int rows) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("departmentCode", entity.getDepartmentCode());
			parmsMap.put("departmentName", entity.getDepartmentName());
			parmsMap.put("parentId", entity.getParentId());
			parmsMap.put("type", entity.getType());
			parmsMap.put("isDel", entity.getIsDel());
		}
		if(page!=0 && rows!=0){
			int index = (page-1)*rows;
			int end =rows; 
			parmsMap.put("index", index);
			parmsMap.put("end", end);
		}
		List<AreaDepartmentEntity> ls = areadepartmentDao.selectAreaDepartment(parmsMap);
		if(ls==null){
			ls = new ArrayList<AreaDepartmentEntity>();
		}
		return  ls;
	}

	/**
	 * 查询部门信息总条数
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int queryAreaDepartmentCount(AreaDepartmentEntity entity) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("departmentCode", entity.getDepartmentCode());
			parmsMap.put("departmentName", entity.getDepartmentName());
			parmsMap.put("parentId", entity.getParentId());
			parmsMap.put("type", entity.getType());
			parmsMap.put("isDel", entity.getIsDel());
		}
		return areadepartmentDao.queryAreaDepartmentCount(parmsMap);
	}

	/**
	 * 修改信息
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int updateAreaDepartment(AreaDepartmentEntity entity) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("id", entity.getId());
			parmsMap.put("departmentCode", entity.getDepartmentCode());
			parmsMap.put("departmentName", entity.getDepartmentName());
			parmsMap.put("parentId", entity.getParentId());
			parmsMap.put("type", entity.getType());
			parmsMap.put("isDel", entity.getIsDel());
		}
		return areadepartmentDao.updateAreaDepartment(parmsMap);
	}

	@Override
	public int deleteAreaDepartment(AreaDepartmentEntity entity) {
		// TODO Auto-generated method stub
		return 0;
	}

}
